package com.davidtorma.site.client.panels;

import java.util.List;

import com.davidtorma.site.GalleryImageService;
import com.davidtorma.site.GalleryItem;
import com.davidtorma.site.client.resolver.GalleryImageResolver;
import com.davidtorma.site.client.resolver.impl.GalleryImageResolverImpl;
import com.davidtorma.site.client.services.GalleryImageServiceAsync;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FlowPanel;

/**
 * 
 * @author Ács Ádám
 * 
 */
public class Gallery extends FlowPanel {
	private GalleryImageServiceAsync service = GWT.create(GalleryImageService.class);
	private GalleryImageResolver resolver = new GalleryImageResolverImpl();
	
	public Gallery(String id) {
		super();
		getElement().setId(id);
		getElement().setClassName("clearfix"); /* TODO kívülről kapjon listát róluk */
		init();
	}

	private void init() {
		service.getGalleryItems(galleryCallback);
	}

	private AsyncCallback galleryCallback = new AsyncCallback<List<GalleryItem>>() {
		@Override
		public void onSuccess(List<GalleryItem> result) { 
			for (GalleryItem galleryItem : result) {
				add(resolver.resolve(galleryItem));
			}
		}

		@Override
		public void onFailure(Throwable caught) {
		}
	};
}
